import './index.scss';
import React from 'react';

function MyCheckbox(props) {
  const { children, onChange, checked } = props;

  const createText = () => {
    //如果没有填写内容就不显示
    if (typeof children !== 'string') {
      return '';
    }

    return <span>{children}</span>;
  };

  return (
    <div>
      <input
        type="checkbox"
        className="my-checkbox"
        checked={checked}
        onChange={(e) => onChange(e)}
      />
      {createText()}
    </div>
  );
}

export default MyCheckbox;
